<?php

//UMA new
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Zip;
use App\Http\Resources\ZipResource;
use App\Traits\TestLog;
use App\Http\Controllers\Api\BaseController;

class ZipController extends BaseController
{
    use TestLog;
    /**
     * 根据邮编获取地址
     * 郵便番号に基づいて住所を取得する
     * @param  mixed $request
     * @return json response
     */
    
    public function index(Request $request)
    {
        $code = $request->zip;
        $address = Zip::search($code)->first();
        if (!$address) {
            $this->loginfo(['zip not found']);
            return $this->error('404', ['msg' => '郵便番号が見つかりません']);
        }
        $this->loginfo(['zip found']);
        return $this->success(new ZipResource($address));
    }
}
